package com.bgs.controller;


import com.bgs.entity.User;
import com.bgs.service.RecyclingorderService;
import com.bgs.tool.R;
import com.bgs.tool.RedisUtil;
import com.bgs.utils.DistanceUtils;
import com.bgs.vo.DetailsVo;
import com.bgs.vo.RecyclingorderVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/recyclingorder")
//回收订单
public class RecyclingorderController {
    @Autowired
    private RecyclingorderService recyclingorderService;
    @Autowired
    RedisUtil redisUtil;
    @GetMapping("/getRecyclingorder")
    @ApiOperation(value = "回收订单查")
    public R getRecyclingorder(Integer riderId,Integer roType ,Integer id){
        List<RecyclingorderVo> recyclingorderVo = recyclingorderService.getRecyclingorder(riderId,roType,id);
        return R.ok().data("recyclingorderVo",recyclingorderVo);
    }

    @GetMapping("/getRecyclingorderRoId")
    @ApiOperation(value = "订单详查")
    public R getRecyclingorderRoId(Integer roId){
        System.out.println(roId);
        List<RecyclingorderVo> recyclingorderVoRoId = recyclingorderService.getRecyclingorderRoId(roId);
        return R.ok().data("recyclingorderVoRoId",recyclingorderVoRoId);
    }



    @GetMapping("/getRiderDistance")
    @ApiOperation(value = "距离")
    public R getRiderDistance(Integer roId, Integer roType,Integer riderId,Double longitudeNew2 ,Double latitudeNew2){
        System.out.println(roId);
        System.out.println(longitudeNew2);
        System.out.println(latitudeNew2);
        List<RecyclingorderVo> list = recyclingorderService.getRecyclingorderRoId(roId);
        Double roLongitude = list.get(0).getRoLongitude();
        Double roLatitude = list.get(0).getRoLatitude();
        Double distance = DistanceUtils.getDistance(longitudeNew2, latitudeNew2, roLongitude, roLatitude);
        System.out.println(distance);
        Integer recyclingorderVoRoId = recyclingorderService.getRiderDistance(distance,roId,riderId);
        return R.ok();
    }

    @GetMapping("/uptRecyclingorderRoId")
    @ApiOperation(value = "订单状态修改")
    public R uptRecyclingorderRoId(Integer roId, Integer roType,Integer riderId){
        System.out.println(roId);
        Integer recyclingorderVoRoId = recyclingorderService.uptRecyclingorderRoId(roId,roType,riderId);
        return R.ok().data("recyclingorderVoRoId",recyclingorderVoRoId);
    }

    @GetMapping("/getUserRoId")
    @ApiOperation(value = "骑手查询")
    public R getUserRoId(Integer riderId){
        User userList = recyclingorderService.getUserRoId(riderId);
        return R.ok().data("userList",userList);
    }

    @GetMapping("/getRecyclingorderComplete")
    @ApiOperation(value = "回收订单查")
    public R getRecyclingorderComplete(Integer riderId){
        System.out.println(riderId);
        List<RecyclingorderVo> recyclingorderVo = recyclingorderService.getRecyclingorderComplete(riderId);
        return R.ok().data("recyclingorderVo",recyclingorderVo);
    }

    @GetMapping("/getRecyclingorderCompleted")
    @ApiOperation(value = "回收订单查")
    public R getRecyclingorderCompleted(Integer riderId){
        System.out.println(riderId);
        List<RecyclingorderVo> recyclingorderVo = recyclingorderService.getRecyclingorderCompleted(riderId);
        return R.ok().data("recyclingorderVo",recyclingorderVo);
    }

    @GetMapping("/getRedisRecyclingorder")
    @ApiOperation(value = "回收详情存入redis")
    public R getRedisRecyclingorder( DetailsVo details ,String redisId){
        System.out.println(redisId+"这里");
        System.out.println(details);
        if (details.getRoId() != null) {
            redisUtil.set(details.getRoId(), details);
            Integer id = Integer.parseInt(details.getRoId());
            recyclingorderService.getRedisRecyclingorder(id);
        }
        if (redisId != null){
            Object k = redisUtil.get(redisId);
            System.out.println(k+"这里");
            return R.ok().data("k",k);
        }
        return R.ok();
    }
}
